<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->

<div>
  <div class="page-header">
    <h1 class="page-header__page-title">Integrations</h1>
    <span class="page-header__description"
      >Connect to third-party API gateways and event brokers to create a unified control plane and API portal with Gravitee</span
    >
  </div>

  <mat-card>
    <div class="card-header">
      <div class="card-header__title">
        <h3>Create Integration</h3>
      </div>
      <div class="card-header__actions">
        <button mat-raised-button [disabled]="false" data-testid="exit-create-integration-button" routerLink="..">
          <mat-icon svgIcon="gio:cancel"></mat-icon>
          Exit without saving
        </button>
      </div>
    </div>

    <mat-stepper linear color="accent" [disableRipple]="true">
      <!-- step 1-->
      <mat-step [stepControl]="chooseProviderForm">
        <form [formGroup]="chooseProviderForm" class="form providers">
          <div class="providers__body">
            <ng-template matStepLabel>Choose Provider</ng-template>
            <gio-form-selection-inline formControlName="provider" class="list">
              <gio-form-selection-inline-card
                *ngFor="let provider of integrationProviders.active"
                [value]="provider.value"
                class="gio-radio-button"
              >
                <gio-form-selection-inline-card-content>
                  <gio-card-content-title>
                    {{ provider.name }}
                  </gio-card-content-title>
                </gio-form-selection-inline-card-content>
              </gio-form-selection-inline-card>
            </gio-form-selection-inline>

            <div class="badges">
              <span class="gio-badge-neutral">Coming soon</span>
            </div>

            <gio-form-selection-inline class="list">
              <gio-form-selection-inline-card
                *ngFor="let provider of integrationProviders.comingSoon"
                [value]="provider.value"
                class="gio-radio-button"
                [disabled]="true"
              >
                <gio-form-selection-inline-card-content>
                  <gio-card-content-title>
                    {{ provider.name }}
                  </gio-card-content-title>
                </gio-form-selection-inline-card-content>
              </gio-form-selection-inline-card>
            </gio-form-selection-inline>
          </div>
          <div class="providers__actions">
            <button
              mat-raised-button
              color="primary"
              matStepperNext
              [disabled]="!chooseProviderForm.valid"
              data-testid="create-integration-submit-first-step"
            >
              Next
            </button>
          </div>
        </form>
      </mat-step>

      <!-- step 2 -->
      <mat-step [stepControl]="addInformationForm">
        <form [formGroup]="addInformationForm" class="form" (ngSubmit)="onSubmit()">
          <ng-template matStepLabel>Enter Information</ng-template>
          <div class="form__body">
            <mat-card class="form-card">
              <mat-card-content>
                <div>
                  <h5>General Information</h5>
                  <p class="info">Enter the general information for this new integration.</p>
                </div>
                <div>
                  <mat-form-field appearance="outline" class="form-field">
                    <input
                      id="name"
                      type="text"
                      matInput
                      formControlName="name"
                      required="true"
                      data-testid="create-integration-name-input"
                    />
                    <mat-label>Name</mat-label>
                    <mat-error *ngIf="addInformationForm.get('name').hasError('required')">Integration name is required. </mat-error>
                    <mat-error *ngIf="addInformationForm.get('name').hasError('maxlength')"
                      >Integration name has to be less than 50 characters long.
                    </mat-error>
                    <mat-error *ngIf="addInformationForm.get('name').hasError('minlength')"
                      >Integration name has to be at least 1 characters long.
                    </mat-error>
                  </mat-form-field>
                </div>
                <div>
                  <mat-form-field appearance="outline" class="form-field">
                    <textarea
                      id="description"
                      matInput
                      #input
                      formControlName="description"
                      maxlength="250"
                      rows="2"
                      data-testid="create-integration-description"
                    ></textarea>
                    <mat-label>Description</mat-label>
                    <mat-hint align="start" class="hint">{{ input.value.length }}/250</mat-hint>
                  </mat-form-field>
                </div>
              </mat-card-content>
            </mat-card>
          </div>
          <div class="form__actions">
            <button matStepperPrevious mat-raised-button>Back</button>
            <button
              type="submit"
              mat-raised-button
              color="primary"
              data-testid="create-integration-submit-button"
              [disabled]="!addInformationForm.valid || isLoading"
            >
              Create Integration
            </button>
          </div>
        </form>
      </mat-step>
    </mat-stepper>
  </mat-card>
</div>
